#include "dominion.h"
#include "testutils.h"
#include <stdio.h>
#include <stdlib.h>

// This unit test was added after it was found (via random testing, confirmed
// with code inspection) that the baron card was not discarding itself when
// played.

// Test using a baron to discard an estate card.
void testBaronEffect_discardEstate 
                    (   int args[MAX_PLAYARGS], int cardtypes[MAX_PLAYARGS],
                        carddesc_t desc, struct gameState *g,
                        expectedState_t *expected )
{
    pass_printf (   "%s: TEST discarding %s using %s\n", 
                    __func__, desc[1], desc[0] );
    
    int expectedBuys = g->numBuys + 1;
    int expectedCoins = g->coins + 4;
    
    testPlayCard (args[0], args[1], args[2], args[3], g, expected, false);
    
    assert_equal (g->numBuys, expectedBuys, "verifying the number of buys");
    assert_equal (g->coins, expectedCoins, "verifying the number of coins");
    
    testEndTurn (g, expected);
}

// Test using a baron to gain an estate card.
void testBaronEffect_gainEstate 
                    (   int args[MAX_PLAYARGS], int cardtypes[MAX_PLAYARGS],
                        carddesc_t desc, struct gameState *g,
                        expectedState_t *expected )
{
    pass_printf (   "%s: TEST gaining an estate card using %s\n", 
                    __func__, desc[0] );
    
    int expectedBuys = g->numBuys + 1;
    int expectedCoins = g->coins;
    
    expected->count[estate]++;
    
    testPlayCard (args[0], args[1], args[2], args[3], g, expected, false);
    
    assert_equal (g->numBuys, expectedBuys, "verifying the number of buys");
    assert_equal (g->coins, expectedCoins, "verifying the number of coins");
    
    testEndTurn (g, expected);
}

int main (int argc, char *argv[])
{
    parse_args (argc, argv);
    
    static playargs_t playargs_discardEstate =
    {
        {arg_handcard,  baron, baron},
        {arg_num,       1, 1},
        {arg_num,       0, 0},
        {arg_num,       0, 0},
        {arg_handcard,  estate, estate}
    };
    
    run_cardtest (playargs_discardEstate, testBaronEffect_discardEstate);
    
    static playargs_t playargs_gainEstate =
    {
        {arg_handcard,  baron, baron},
    };
    
    run_cardtest (playargs_gainEstate, testBaronEffect_gainEstate);
}
